home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.4)
-
- import md5
- import sha
- import hmac
-
- def check_hash_module(module, key = None):
- if not hasattr(module, 'digest_size'):
- raise AssertionError, 'Must have digest_size'
- if not module.digest_size is None and module.digest_size > 0:
- raise AssertionError, 'digest_size must be None or positive'
- if key is not None:
- obj1 = module.new(key)
- obj2 = module.new(key, 'string')
- h1 = module.new(key, 'string').digest()
- obj3 = module.new(key)
- obj3.update('string')
- h2 = obj3.digest()
- if not h1 == h2:
- raise AssertionError, 'Hashes must match'
- else:
- obj1 = module.new()
- obj2 = module.new('string')
- h1 = module.new('string').digest()
- obj3 = module.new()
- obj3.update('string')
- h2 = obj3.digest()
- if not h1 == h2:
- raise AssertionError, 'Hashes must match'
- if not hasattr(obj1, 'digest_size'):
- raise AssertionError, 'Objects must have digest_size attr'
- if module.digest_size is not None:
- if not obj1.digest_size == module.digest_size:
- raise AssertionError, 'digest_size must match'
-
- if not obj1.digest_size == len(h1):
- raise AssertionError, 'digest_size must match actual size'
- obj1.update('string')
- obj_copy = obj1.copy()
- if not obj1.digest() == obj_copy.digest():
- raise AssertionError, 'Copied objects must match'
- if not obj1.hexdigest() == obj_copy.hexdigest():
- raise AssertionError, 'Copied objects must match'
- digest = obj1.digest()
- hexdigest = obj1.hexdigest()
- hd2 = ''
- for byte in digest:
- hd2 += '%02x' % ord(byte)
-
- if not hd2 == hexdigest:
- raise AssertionError, "hexdigest doesn't appear correct"
- print 'Module', module.__name__, 'seems to comply with PEP 247'
-
- if __name__ == '__main__':
- check_hash_module(md5)
- check_hash_module(sha)
- check_hash_module(hmac, key = 'abc')
-
-